geometry *2000

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;


#define ElGed_Sevawy  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define ld long double
#define el '\n'
#define pi acos(-1)
#define F first
#define S second
#define sz(x) (int)(x).size()

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());
ll rand(ll l, ll r){
    return uniform_int_distribution<ll>(l, r)(gen);
}

const ll N = 2e5 + 5, M = 1e6 + 5, MOD1 = 1e9 + 7, MOD2 = 1e9 + 9, lg = 21, INF  = 2e18 + 5, P1 = 29, P2 = 31;
struct Circle{
    ld x, y, r;
};
ld CircleIntersection(Circle A, Circle B) {
    ld d, alpha, beta, a1, a2;
    ld ans;
    d = sqrt((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y));

    if (d > A.r + B.r) ans = 0;

    else if (d <= abs(B.r - A.r) && A.r >= B.r)
        ans = pi * B.r * B.r;

    else if (d <= abs(B.r - A.r) && B.r >= A.r)
        ans = pi * A.r * A.r;

    else {
        alpha = acos((A.r * A.r + d * d - B.r * B.r) / (2 * A.r * d)) * 2;
        beta = acos((B.r * B.r + d * d - A.r * A.r) / (2 * B.r * d)) * 2;
        a1 = 0.5 * beta * B.r * B.r - 0.5 * B.r * B.r * sin(beta);
        a2 = 0.5 * alpha * A.r * A.r - 0.5 * A.r * A.r * sin(alpha);
        ans = a1 + a2;
    }
    return ans;
}
void go() {
    Circle c1, c2;
    cin >> c1.x >> c1.y >> c1.r >> c2.x >> c2.y >> c2.r;
    cout << fixed << setprecision(6) << CircleIntersection(c1, c2) << el;
}
int32_t main() {
    ElGed_Sevawy
    int tc = 1;
    //cin >> tc;
    while (tc--)
        go();
}
	     		  	    			    		 	 	 		


Comments

Submit
0 Comments
More Questions

1569C - Jury Meeting
108A - Palindromic Times
46A - Ball Game
114A - Cifera
776A - A Serial Killer
25B - Phone numbers
1633C - Kill the Monster
1611A - Make Even
1030B - Vasya and Cornfield
1631A - Min Max Swap
1296B - Food Buying
133A - HQ9+
1650D - Twist the Permutation
1209A - Paint the Numbers
1234A - Equalize Prices Again
1613A - Long Comparison
1624B - Make AP
660B - Seating On Bus
405A - Gravity Flip
499B - Lecture
709A - Juicer
1358C - Celex Update
1466B - Last minute enhancements
450B - Jzzhu and Sequences
1582C - Grandma Capa Knits a Scarf
492A - Vanya and Cubes
217A - Ice Skating
270A - Fancy Fence
181A - Series of Crimes
1638A - Reverse